package com.onec.service.channel.service.impl;

import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import com.onec.service.channel.dao.ChannelInfoRepository;
import com.onec.service.channel.entity.ChannelInfo;
import com.onec.service.channel.service.ChannelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 处理机构信息，
 *
 * @author onec
 * @serial
 * @since 20200810
 */
@Service
public class ChannelInfoServiceImpl implements ChannelInfoService {

    @Autowired
    ChannelInfoRepository channelInfoRepository;

    /**
     * 通过机构id 获取机构。
     *
     * @param id
     * @return
     */
    @Override
    public ChannelInfo getChannelInfoById(long id) {
        return channelInfoRepository.findById(id).get();
    }

    @Override
    public ChannelInfo getChannelInfoByNo(String channelNo) {
        ChannelInfo channelInfo = channelInfoRepository.findByNo(channelNo);
        if (!Optional.ofNullable(channelInfo).isPresent()) {

        }
        if (StatusEnum.isSuccess(channelInfo.getStatus())) {

        }
        return channelInfo;
    }

    @Override
    public List<ChannelInfo> getAvailableChannelInfoProduct(ProductEnum productEnum) {
        return channelInfoRepository.findByProductAndStatus(productEnum, StatusEnum.SUCCESS);
    }
}
